using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UISettingPanel : BasePanel
{
    public SliderToggerNode effect, music;
    public Slider effectSlider, musicSlider;


    public override void Init()
    {
        effectSlider.onValueChanged.AddListener(OnEffectSlider);
        musicSlider.onValueChanged.AddListener(OnMusicSlider);
        effect.Toggle.onValueChanged.AddListener(OnEffectToggle);
        music.Toggle.onValueChanged.AddListener(OnMusicToggle);
    }



    public override void Open(Vector3 pos, Vector3 size)
    {
        base.Open(pos, size);
        Refresh();
    }

    public override void Close()
    {
        base.Close();
        MainMgr.Instance.isSavePlayerSettingData = true;
    }

    public void Refresh()
    {
        effectSlider.value = MainMgr.Instance.GetVolum(SoundStyle.effect);
        musicSlider.value = MainMgr.Instance.GetVolum(SoundStyle.backGround);
        effect.SetToggleState(MainMgr.Instance.GetMute(SoundStyle.effect));
        music.SetToggleState(MainMgr.Instance.GetMute(SoundStyle.backGround));
    }

    void OnEffectSlider(float value)
    {
        MainMgr.Instance.SetVolum(SoundStyle.effect, value);
    }

    void OnMusicSlider(float value)
    {
        MainMgr.Instance.SetVolum(SoundStyle.backGround, value);
    }

    void OnEffectToggle(bool isOn)
    {
        MainMgr.Instance.SetMute(SoundStyle.effect, isOn);
    }

    void OnMusicToggle(bool isOn)
    {
        MainMgr.Instance.SetMute(SoundStyle.backGround, isOn);
    }
       

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {

    }
    

}
